<?php
namespace app\api\model;
use think\Model;
use think\model\concern\SoftDelete;
class EscortType extends Model
{
    use SoftDelete;
    protected $name = "escort_type";
    protected $pk = "id";
    protected $deleteTime = "delete_time";
    protected $defaultSoftDelete = 0;
    protected $json = [];
    protected $jsonAssoc = true;
    public function getImgAttr($value){
        if($value){
            $value = getAppFilePath($value);
        }else{
            $value = '';
        }
        return $value;
    }
    public function getChild($id){
        $child = $this->where('pid',$id)
            ->where('status',1)
            ->field('id,name,img,introduce')
            ->order('sort desc')
            ->select()->toArray();
        if(empty($child)){
            return [];
        }
        foreach ($child as $key=>$value){
            $value['child'] = $this->getChild($value['id']);
            $child[$key] = $value;
        }
        return $child;
    }
}